package com.example.rocketmq.demo.consumer;

import com.example.rocketmq.demo.config.RocketMQConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.ConsumeMode;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * 基于注解方式的顺序消息消费者
 */
@Slf4j
@Component
@RocketMQMessageListener(
        topic = RocketMQConstant.TOPIC_ORDER,
        consumerGroup = "annotation-orderly-consumer-group",
        consumeMode = ConsumeMode.ORDERLY // 顺序消费模式
)
public class AnnotationOrderlyConsumer implements RocketMQListener<String> {

    @Override
    public void onMessage(String message) {
        log.info("注解方式-接收到顺序消息: {}", message);
        
        // 模拟业务处理
        try {
            // 处理业务逻辑
            Thread.sleep(500);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}